package com.znsd.zl.app.housecollect.controller;

import com.znsd.zl.app.housecollect.entity.HouseCollectEntity;
import com.znsd.zl.app.housecollect.service.impl.HouseCollectServiceImpl;
import com.znsd.zl.app.housecollect.vo.HouseCollectPageReqVO;
import com.znsd.zl.utils.BaseController;
import com.znsd.zl.utils.PageUtils;
import com.znsd.zl.utils.R;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName HouseCollectController
 * @Description 房屋收藏控制器接口
 * @Author jaypdd
 * @Date 2020/8/22 20:51
 * @Version v1.0
 */
@RestController
@RequestMapping("/collect")
public class HouseCollectController extends BaseController<HouseCollectServiceImpl, HouseCollectEntity, Integer> {

	/**
	 * 用户取消房屋收藏
	 * @param id 取消收藏的用户房屋中介数据表id
	 * @return 成功 code:200 失败500
	 */
	@DeleteMapping("/cancel/{id}")
	public R cancelHouseCollect(@PathVariable("id") Integer id) {
		try {
			return super.service.removeById(id) ? R.ok("取消成功") : R.error("取消失败");
		} catch (Exception e) {
			e.printStackTrace();
			return R.error();
		}
	}

	/**
	 * 分页查询用户收藏的所有房屋信息
	 * @param reqVO 请求参数vo
	 * @return 成功 code:200 失败 500
	 */
	@GetMapping("/page")
	public R pageFind(@RequestBody HouseCollectPageReqVO reqVO) {
		// @RequestParam(value = "pageNum") Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize
		return R.ok().put("page", new PageUtils(super.service.queryPage(reqVO)));
	}
}
